/*
 * @Author: Dufen~123 dufen.0
 * @Date: 2024-11-26 14:07:23
 * @LastEditors: Dufen~123 dufen.0
 * @LastEditTime: 2024-11-28 18:26:54
 * @FilePath: \vite-project\src\view\login.jsx Login登录页面
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import React from 'react';
import  {useNavigate,Navigate} from "react-router-dom";
import './login.css';
import { Button,  Form, Input, message } from 'antd';

import { getMenu } from '../../api/index';


const Login = () => {
  const [form] = Form.useForm();
  // 重置按钮
      // const onReset = (form) => {
      //   form.resetFields();
      // };
    // 登录事件
const onFinish = (val) => {
  navigate('/')
     // console.log('val',val)//val就是用户名和密码，应该是组件中onFinish自动传过来的
    //  if (!val.password || !val.username) {
    //   messageApi.open({
    //     type: "warning",
    //     content: "请输入用户名或密码",
    //   });
    // } else {
    //   getMenu(val).then(({ data }) => {//把data从成功的Promise中解构出来
    //     localStorage.setItem("token", data.data.token);
    //     navigate('/home')
    //   });
    //   
    // }
  };

    const [messageApi, contextHolder] = message.useMessage();
    const navigate=useNavigate()
    // 登录过了(有token)
    // if(localStorage.getItem('token')){
    //   return <Navigate to='/home' replace></Navigate>
    // }
    return(
<Form
  className='login-container'
    name="basic"
    form={form}
    style={{
      maxWidth: 600,
    }}
    initialValues={{
      remember: true,
    }}
    onFinish={onFinish}
    autoComplete="off"
  >
    <div className="login_title ">系统登录</div> 
    <Form.Item
      label="账号"
      name="username"
      rules={[
        {
          required: true,
          message: '请输入账号!',
        },
      ]}
    >
      <Input />
    </Form.Item>

    <Form.Item
      label="密码"
      name="password"
      rules={[
        {
          required: true,
          message: '请输入密码!',
        },
      ]}
    >
      <Input.Password />
    </Form.Item>
    <Form.Item label={null} className="login-button">
      <Button  htmlType="button" className="login-button-resetFields"  onClick={() => {form.resetFields();}}>
        取消
      </Button>
      <Button type="primary" htmlType="submit" onClick={onFinish}>
        登录
      </Button>
    </Form.Item>
   
  </Form>
    )
}
export default Login;


